package 力扣;
//二分查找


public class leetcode704 {
    public static void main(String[] args) {

    }
    public int search(int[] nums, int target) {

        int a=binarySearch(nums,target);
        return a;
    }

    private int binarySearch(int[] nums, int target) {
        int high=nums.length-1;
        int low=0;
        int mid=(low+high)/2;
        while(true){

            if(nums[mid]==target){
                return mid;
            }
            if(low>=high) return -1;
            if(nums[mid]>target){
                high=mid-1;
            }
            if(nums[mid]<target){
                low=mid+1;
            }
            mid=(low+high)/2;
        }
    }

}
